﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EmotionRecognitionMessages;
using EmotionRecognitionEntities;

namespace EmotionRecognitionGui
{
    public partial class UserLogin : BasicForm
    {
        GuiManager guiManager;

        public UserLogin()//
        {
            try
            {
                guiManager = GuiManager.Instance;
                InitializeComponent();
                passwordTextBox.UseSystemPasswordChar = true;
            }
            catch (Exception e)
            {
                MessageBox.Show("Error: " + e.ToString());
            }
        }


        protected void registerButton_Click(object sender, EventArgs e)
        {
            guiManager.SwitchForms(this, guiManager.registerationGui);
        }


        public void ClearControls()
        {
            this.ErrorLabel.Visible = false;
            this.userNameTextBox.Text = string.Empty;
            this.passwordTextBox.Text = string.Empty;
        }

        protected void loginButton_Click(object sender, EventArgs e)
        {
            Messages ulm = new Messages();
            ReplyMsg replyMsg = ulm.LoginAuthentication(passwordTextBox.Text, userNameTextBox.Text);
            if (replyMsg.MessageState == true)
            {
                object[] obj = replyMsg.ParamArray;
                //SetCurrentUser
                guiManager.currentuserID = (int)obj[0];
                if ((Boolean)obj[1].Equals(Convert.ToBoolean(true)))
                {
                    guiManager.SwitchForms(this, guiManager.mainMenuExpertGui);
                }
                else
                {
                    guiManager.SwitchForms(this, guiManager.mainMenuReviewerGui);
                }


            }

            else
            {
                userNameTextBox.Text = string.Empty;
                passwordTextBox.Text = string.Empty;

                this.ErrorLabel.Visible = true; 

            }

        }

      
    }
}
